﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.DirectoryServices.AccountManagement;

public partial class Account_Login : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        { 
            
        }

        var returnUrl = HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);

        if (!String.IsNullOrEmpty(returnUrl))
        {
            
        }
    }

    protected void Unnamed6_Click(object sender, EventArgs e)
    {
        
    }

    protected void Unnamed1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        bool isValid = false;
        String domain = System.Configuration.ConfigurationSettings.AppSettings["Domain"].ToString();

        using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, domain))
        {
            // validate the credentials
            isValid = pc.ValidateCredentials(login.UserName, login.Password);
        }

        if (isValid)
            e.Authenticated = true;
        else
            e.Authenticated = false;
       
    }
}